package com.xqzgj.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xqzgj.system.mapper.StockInfoMapper;
import com.xqzgj.system.domain.StockInfo;
import com.xqzgj.system.service.IStockInfoService;

/**
 * 库存信息Service业务层处理
 */
@Service
public class StockInfoServiceImpl implements IStockInfoService {
    @Autowired
    private StockInfoMapper stockInfoMapper;

    /**
     * 查询库存信息列表
     */
    @Override
    public List<StockInfo> selectStockInfoList(StockInfo stockInfo) {
        return stockInfoMapper.selectStockInfoList(stockInfo);
    }

    /**
     * 查询库存信息
     */
    @Override
    public StockInfo selectStockInfoById(Long id) {
        return stockInfoMapper.selectStockInfoById(id);
    }

    /**
     * 新增库存信息
     */
    @Override
    public int insertStockInfo(StockInfo stockInfo) {
        return stockInfoMapper.insertStockInfo(stockInfo);
    }

    /**
     * 修改库存信息
     */
    @Override
    public int updateStockInfo(StockInfo stockInfo) {
        return stockInfoMapper.updateStockInfo(stockInfo);
    }

    /**
     * 批量删除库存信息
     */
    @Override
    public int deleteStockInfoByIds(Long[] ids) {
        return stockInfoMapper.deleteStockInfoByIds(ids);
    }

    /**
     * 删除库存信息
     */
    @Override
    public int deleteStockInfoById(Long id) {
        return stockInfoMapper.deleteStockInfoById(id);
    }

    /**
     * 校验商品编码是否唯一
     */
    @Override
    public boolean checkGoodsCodeUnique(StockInfo stockInfo) {
        Long id = stockInfo.getId() == null ? -1L : stockInfo.getId();
        StockInfo info = stockInfoMapper.checkGoodsCodeUnique(stockInfo.getGoodsCode());
        return info == null || info.getId().equals(id);
    }

    /**
     * 校验商品名称是否唯一
     */
    @Override
    public boolean checkGoodsNameUnique(StockInfo stockInfo) {
        Long id = stockInfo.getId() == null ? -1L : stockInfo.getId();
        StockInfo info = stockInfoMapper.checkGoodsNameUnique(stockInfo.getGoodsName());
        return info == null || info.getId().equals(id);
    }

    /**
     * 更新库存数量
     */
    @Override
    public int updateStockQuantity(StockInfo stockInfo) {
        return stockInfoMapper.updateStockQuantity(stockInfo);
    }

    /**
     * 更新库存状态
     */
    @Override
    public int updateStockStatus(StockInfo stockInfo) {
        return stockInfoMapper.updateStockStatus(stockInfo);
    }
}